const { validationResult } = require("express-validator");
import type { Request, Response, NextFunction } from "express";
import { handleError, handleSucceed } from "@/utils/stateHandle";

// 封装检验
export const validateResult = (
  req: Request,
  res: Response,
  next: NextFunction
) => {
  try {
    validationResult(req).throw();
    if (req.body.email) {
      req.body.email = req.body.email.toLowerCase();
    }
    return next();
  } catch (err) {
    return handleError(res, err, 201);
  }
};
